package huawei.widget;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.MotionEvent;
import android.view.View.MeasureSpec;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewParent;
import android.widget.PopupWindow;
import android.widget.SeekBar;
import android.widget.TextView;
import com.huawei.appgallery.festivalanimation.particle.modifiers.SizeModifier;
import java.util.Locale;
import o.fo;
import o.fqi.c;
import o.fqi.e;

public class HwSeekBar extends SeekBar {
    private int ʻ;
    private int ʻॱ;
    private boolean ʼ;
    private Paint ʼॱ;
    private boolean ʽ;
    private int ʽॱ;
    private Rect ʾ;
    private Paint ʿ;
    private int ˈ;
    private PopupWindow ˊ;
    private float ˊˊ;
    private a ˊˋ;
    private int ˊॱ;
    private boolean ˊᐝ;
    private boolean ˋ;
    private int ˋॱ;
    private boolean ˎ;
    private float ˏ;
    private int ˏॱ;
    private float ͺ;
    private Context ॱ;
    private int ॱˊ;
    private int ॱˋ;
    private int ॱˎ;
    private Drawable ॱॱ;
    private int ॱᐝ;
    private TextView ᐝ;
    private int ᐝॱ;

    public interface a {
        void ˎ(HwSeekBar hwSeekBar);

        void ˎ(HwSeekBar hwSeekBar, int i, boolean z);

        void ॱ(HwSeekBar hwSeekBar);
    }

    public HwSeekBar(Context context) {
        this(context, null);
    }

    public HwSeekBar(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwSeekBar(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˎ = false;
        this.ˋ = false;
        this.ʽ = false;
        this.ʼ = false;
        this.ʻ = 0;
        this.ʾ = new Rect();
        ˎ(context, attributeSet, i);
    }

    private static int ˊ(int i) {
        return (int) TypedValue.applyDimension(1, (float) i, Resources.getSystem().getDisplayMetrics());
    }

    private static Bitmap ˏ(Drawable drawable) {
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }
        try {
            Bitmap createBitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
            Canvas canvas = new Canvas(createBitmap);
            drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
            drawable.draw(canvas);
            return createBitmap;
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    private void ˎ(Context context, AttributeSet attributeSet, int i) {
        this.ॱ = context;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, e.ʾ, i, c.ˋ);
        this.ʼ = obtainStyledAttributes.getBoolean(e.ˊᐝ, false);
        this.ॱᐝ = obtainStyledAttributes.getDimensionPixelSize(e.ˋˋ, this.ॱᐝ);
        this.ᐝॱ = obtainStyledAttributes.getDimensionPixelSize(e.ˋᐝ, this.ᐝॱ);
        this.ʻॱ = obtainStyledAttributes.getResourceId(e.ˋˊ, 0);
        this.ॱˎ = obtainStyledAttributes.getResourceId(e.ˊˊ, 0);
        this.ॱˋ = obtainStyledAttributes.getColor(e.ˊˋ, this.ॱˋ);
        this.ʽॱ = obtainStyledAttributes.getColor(e.ˉ, this.ʽॱ);
        obtainStyledAttributes.recycle();
        if (this.ʼ) {
            ˊ();
            this.ˊॱ = this.ʻॱ;
        }
        this.ˈ = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    public void setOnSeekBarChangeListener(a aVar) {
        this.ˊˋ = aVar;
    }

    protected void drawableStateChanged() {
        super.drawableStateChanged();
        Drawable progressDrawable = getProgressDrawable();
        if (progressDrawable != null) {
            progressDrawable.setAlpha(isEnabled() ? 255 : 76);
        }
        if (this.ॱॱ != null) {
            this.ॱॱ.setState(getDrawableState());
        }
    }

    public void setTip(boolean z, int i, boolean z2) {
        if (i != 0) {
            this.ˎ = true;
            this.ˋ = z;
            this.ˋॱ = i;
            this.ͺ = ((float) getMax()) / ((float) this.ˋॱ);
            this.ˊॱ = z2 ? this.ʻॱ : this.ॱˎ;
            this.ॱॱ = fo.ˊ(this.ॱ, o.fqi.a.ॱ);
            ˊ();
            this.ʼॱ = new Paint();
            this.ʼॱ.setAntiAlias(true);
            this.ʿ = new Paint();
            this.ʿ.setAntiAlias(true);
            this.ʿ.setColor(this.ʽॱ);
            this.ʿ.setTextSize((float) this.ॱᐝ);
            this.ʿ.setTypeface(Typeface.create("HwChinese-medium", 0));
            if (this.ˋ) {
                getLayoutParams().height = ˊ(48);
            }
            setProgress(getProgress());
            invalidate();
        }
    }

    public void setTipText(String str) {
        if (this.ˊॱ == this.ʻॱ && this.ʼ && str != null) {
            this.ᐝ.setText(str);
            ॱॱ();
            this.ʽ = true;
            return;
        }
        this.ʽ = false;
    }

    void ˋ() {
        this.ˊᐝ = true;
        if (this.ˊˋ != null) {
            this.ˊˋ.ˎ(this);
        }
        ʽ();
    }

    void ˎ() {
        this.ˊᐝ = false;
        if (this.ˊˋ != null) {
            this.ˊˋ.ॱ(this);
        }
        ʼ();
    }

    private void ˊ() {
        this.ᐝ = new TextView(this.ॱ);
        this.ᐝ.setTextColor(this.ॱˋ);
        this.ᐝ.setTextSize(0, (float) this.ᐝॱ);
        this.ᐝ.setTypeface(Typeface.SANS_SERIF);
        if (this.ˊॱ == this.ॱˎ) {
            Drawable ˊ = fo.ˊ(this.ॱ, this.ˊॱ);
            if (ˊ != null) {
                this.ᐝ.setLayoutParams(new LayoutParams(ˊ.getIntrinsicWidth(), ˊ.getIntrinsicHeight()));
            } else {
                this.ᐝ.setLayoutParams(new LayoutParams(-2, -2));
            }
            this.ᐝ.setGravity(17);
        } else {
            this.ᐝ.setLayoutParams(new LayoutParams(-2, -2));
            this.ᐝ.setGravity(17);
        }
        this.ᐝ.setSingleLine(true);
        this.ˊ = new PopupWindow(this.ᐝ, -2, -2, false);
    }

    protected synchronized void onDraw(Canvas canvas) {
        if (!this.ˎ) {
            ˋ(canvas);
            ˊ(canvas);
        } else if (this.ˋ) {
            int save = canvas.save();
            canvas.translate(0.0f, (float) (0 - ˊ(4)));
            ˋ(canvas);
            ˎ(canvas);
            ˊ(canvas);
            canvas.restoreToCount(save);
        } else {
            ˋ(canvas);
            ˎ(canvas);
            ˊ(canvas);
        }
    }

    void ˋ(Canvas canvas) {
        Drawable progressDrawable = getProgressDrawable();
        if (progressDrawable != null) {
            int save = canvas.save();
            if (ˊॱ()) {
                canvas.translate((float) (getWidth() - getPaddingRight()), (float) getPaddingTop());
                canvas.scale(SizeModifier.STABLE_STATE_SCALE, 1.0f);
            } else {
                canvas.translate((float) getPaddingLeft(), (float) getPaddingTop());
            }
            progressDrawable.draw(canvas);
            canvas.restoreToCount(save);
        }
    }

    void ˊ(Canvas canvas) {
        Drawable thumb = getThumb();
        if (thumb != null) {
            int save = canvas.save();
            if (VERSION.SDK_INT <= 19 && this.ˎ && this.ˋ) {
                canvas.translate((float) (getPaddingLeft() - getThumbOffset()), (float) (getPaddingTop() + ˊ(4)));
            } else {
                canvas.translate((float) (getPaddingLeft() - getThumbOffset()), (float) getPaddingTop());
            }
            thumb.draw(canvas);
            canvas.restoreToCount(save);
        }
    }

    public boolean onTouchEvent(MotionEvent motionEvent) {
        if (!isEnabled()) {
            return false;
        }
        switch (motionEvent.getAction()) {
            case 0:
                if (!ॱ()) {
                    ˋ(motionEvent);
                    break;
                }
                this.ˊˊ = motionEvent.getX();
                break;
            case 1:
                if (this.ˊᐝ) {
                    ॱ(motionEvent);
                    ˎ();
                    setPressed(false);
                } else {
                    ˋ();
                    ॱ(motionEvent);
                    ˎ();
                }
                invalidate();
                break;
            case 2:
                if (!this.ˊᐝ) {
                    if (Math.abs(motionEvent.getX() - this.ˊˊ) > ((float) this.ˈ)) {
                        ˋ(motionEvent);
                        break;
                    }
                }
                ॱ(motionEvent);
                break;
                break;
            case 3:
                if (this.ˊᐝ) {
                    ˎ();
                    setPressed(false);
                }
                invalidate();
                break;
        }
        return true;
    }

    private boolean ॱ() {
        ViewParent parent = getParent();
        while (parent != null && (parent instanceof ViewGroup)) {
            if (((ViewGroup) parent).shouldDelayChildPressedState()) {
                return true;
            }
            parent = parent.getParent();
        }
        return false;
    }

    private void ˋ(MotionEvent motionEvent) {
        setPressed(true);
        if (getThumb() != null) {
            invalidate(getThumb().getBounds());
        }
        ˋ();
        ॱ(motionEvent);
        ˏ();
    }

    private void ॱ(MotionEvent motionEvent) {
        float f = 1.0f;
        float f2 = 0.0f;
        int round = Math.round(motionEvent.getX());
        Math.round(motionEvent.getY());
        int width = getWidth();
        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int i = (width - paddingLeft) - paddingRight;
        if (i <= 0) {
            setProgress(0);
            return;
        }
        if (ˊॱ()) {
            if (round > width - paddingRight) {
                f = 0.0f;
            } else if (round >= paddingLeft) {
                f = ((float) ((i - round) + paddingLeft)) / ((float) i);
                f2 = this.ˏ;
            }
        } else if (round < paddingLeft) {
            f = 0.0f;
        } else if (round <= width - paddingRight) {
            f = ((float) (round - paddingLeft)) / ((float) i);
            f2 = this.ˏ;
        }
        setProgress(Math.round(f2 + (f * ((float) getMax()))));
    }

    private void ˏ() {
        ViewParent parent = getParent();
        if (parent != null) {
            parent.requestDisallowInterceptTouchEvent(true);
        }
    }

    private void ʽ() {
        if (this.ʼ) {
            this.ᐝ.setBackgroundResource(this.ˊॱ);
            this.ˊ.showAsDropDown(this, 0, 0, 3);
            ॱॱ();
        }
    }

    private void ʼ() {
        if (this.ʼ) {
            this.ˊ.dismiss();
        }
    }

    public synchronized void setProgress(int i) {
        Object obj = null;
        synchronized (this) {
            if (this.ˎ) {
                i = Math.round(this.ͺ * ((float) Math.round(((float) i) / this.ͺ)));
            }
            if (this.ʻ != i) {
                obj = 1;
            }
            this.ʻ = i;
            super.setProgress(i);
            if (!(obj == null || this.ˊˋ == null)) {
                this.ˊˋ.ˎ(this, this.ʻ, false);
            }
            if (this.ʼ) {
                if (!this.ʽ) {
                    this.ᐝ.setText(String.valueOf(this.ʻ));
                }
                ॱॱ();
            }
        }
    }

    private float ʻ() {
        int max = getMax();
        return max > 0 ? ((float) getProgress()) / ((float) max) : 0.0f;
    }

    private void ॱॱ() {
        ᐝ();
        int width = (getWidth() - getPaddingLeft()) - getPaddingRight();
        this.ˊ.update(this, (Math.round((ˊॱ() ? 1.0f - ʻ() : ʻ()) * ((float) width)) + getPaddingLeft()) - (this.ॱˊ / 2), (0 - getMeasuredHeight()) - this.ᐝ.getHeight(), this.ॱˊ, this.ˏॱ);
    }

    private void ᐝ() {
        this.ᐝ.measure(MeasureSpec.makeMeasureSpec(0, 0), MeasureSpec.makeMeasureSpec(0, 0));
        this.ॱˊ = this.ᐝ.getMeasuredWidth();
        this.ˏॱ = this.ᐝ.getMeasuredHeight();
    }

    private void ˎ(Canvas canvas) {
        int i = 1;
        if (this.ॱॱ != null) {
            int intrinsicWidth = this.ॱॱ.getIntrinsicWidth();
            int intrinsicHeight = this.ॱॱ.getIntrinsicHeight();
            float width = (float) ((getWidth() - getPaddingLeft()) - getPaddingRight());
            int i2 = this.ˋॱ;
            int height = (((getHeight() - getPaddingTop()) - getPaddingBottom()) / 2) - (intrinsicHeight / 2);
            int paddingLeft = getPaddingLeft();
            if (i2 > 1) {
                width /= (float) i2;
                if (this.ˋ) {
                    for (intrinsicWidth = 0; intrinsicWidth <= i2; intrinsicWidth++) {
                        if (ˊॱ()) {
                            i = Math.round(this.ͺ * ((float) (i2 - intrinsicWidth)));
                        } else {
                            i = Math.round(this.ͺ * ((float) intrinsicWidth));
                        }
                        canvas.drawText(String.valueOf(i), (((float) paddingLeft) + (((float) intrinsicWidth) * width)) - ((float) (ˋ(String.valueOf(i)) / 2)), (float) (ˏ(String.valueOf(i)) + ((height + intrinsicHeight) + ˊ(16))), this.ʿ);
                    }
                    return;
                }
                Bitmap ˏ = ˏ(this.ॱॱ);
                if (ˏ != null) {
                    while (i < i2) {
                        canvas.drawBitmap(ˏ, (((float) paddingLeft) + (((float) i) * width)) - ((float) (intrinsicWidth / 2)), (float) height, this.ʼॱ);
                        i++;
                    }
                }
            }
        }
    }

    private int ˋ(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        this.ʿ.getTextBounds(str, 0, str.length(), this.ʾ);
        return this.ʾ.width();
    }

    private int ˏ(String str) {
        if (TextUtils.isEmpty(str)) {
            return -1;
        }
        this.ʿ.getTextBounds(str, 0, str.length(), this.ʾ);
        return this.ʾ.height();
    }

    private boolean ˊॱ() {
        if (VERSION.SDK_INT < 17) {
            return false;
        }
        if (getLayoutDirection() == 1) {
            return true;
        }
        return false;
    }

    public int getLayoutDirection() {
        if ("ur".equals(Locale.getDefault().getLanguage())) {
            return 0;
        }
        return super.getLayoutDirection();
    }
}
